#!/bin/bash
# 通用子模块镜像管理器 - Shell 包装器

GIT_CMD="/c/Program Files/Git/bin/git.exe"
PYTHON_SCRIPT="$(dirname "$0")/universal_mirror_manager.py"

show_help() {
    echo "通用子模块镜像管理器"
    echo "自动发现、评估和配置最优镜像"
    echo ""
    echo "使用方法: $0 <command>"
    echo ""
    echo "命令:"
    echo "  setup   为所有子模块自动寻找并配置最优镜像"
    echo "  init    初始化子模块（使用配置的镜像）"
    echo "  check   检查当前镜像配置"
    echo "  test    测试单个项目的镜像发现"
    echo "  help    显示此帮助信息"
}

case "$1" in
    "setup")
        echo "=== 自动设置子模块镜像 ==="
        python "$PYTHON_SCRIPT" --git-cmd "$GIT_CMD" --setup
        ;;
    "init")
        echo "=== 初始化子模块 ==="
        python "$PYTHON_SCRIPT" --git-cmd "$GIT_CMD" --init
        ;;
    "check")
        echo "=== 检查镜像配置 ==="
        python "$PYTHON_SCRIPT" --git-cmd "$GIT_CMD" --check
        ;;
    "test")
        if [ -z "$2" ]; then
            echo "请提供要测试的 Git URL"
            echo "示例: $0 test https://github.com/libexpat/libexpat"
            exit 1
        fi
        echo "=== 测试镜像发现 ==="
        python "$PYTHON_SCRIPT" --git-cmd "$GIT_CMD" --setup
        ;;
    "help"|"")
        show_help
        ;;
    *)
        echo "未知命令: $1"
        show_help
        exit 1
        ;;
esac
